package cn.lili.modules.distribution.entity.dos;

import cn.lili.common.utils.BeanUtil;
import cn.lili.modules.distribution.entity.dto.DistributionApplyDTO;
import cn.lili.modules.distribution.entity.enums.DistributionStatusEnum;
import cn.lili.mybatis.model.BaseStandardEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 分销员对象
 *
 * @author pikachu
 * @since 2020-03-14 23:04:56
 */
@Data
@ApiModel(value = "分销员")
@TableName("li_distribution")
@NoArgsConstructor
public class Distribution extends BaseStandardEntity {


    private static final long serialVersionUID = -4878132663540847325L;

    public Distribution(String memberId, String memberName, DistributionApplyDTO distributionApplyDTO) {
        this.memberId = memberId;
        this.memberName = memberName;
        this.level = 0;
        this.directOrderNumber = 0;
        distributionOrderCount = 0;
        this.distributionStatus = DistributionStatusEnum.APPLY.name();
        BeanUtil.copyProperties(distributionApplyDTO, this);
    }

    @ApiModelProperty(value = "会员id")
    private String memberId;

    @ApiModelProperty(value = "会员名称")
    private String memberName;

    @ApiModelProperty(value = "会员姓名")
    private String name;

    @ApiModelProperty(value = "身份证号")
    private String idNumber;

    @ApiModelProperty(value = "分润总额")
    private Double rebateTotal = 0D;


    @ApiModelProperty(value = "分销订单数")
    private Integer distributionOrderCount;

    /**
     * @see DistributionStatusEnum
     */
    @ApiModelProperty(value = "分销员状态", required = true)
    private String distributionStatus;

    @Length(min = 1, max = 200, message = "结算银行开户行名称长度为1-200位")
    @NotBlank(message = "结算银行开户行名称不能为空")
    @ApiModelProperty(value = "结算银行开户行名称")
    private String settlementBankAccountName;

    @Length(min = 1, max = 200, message = "结算银行开户账号长度为1-200位")
    @NotBlank(message = "结算银行开户账号不能为空")
    @ApiModelProperty(value = "结算银行开户账号")
    private String settlementBankAccountNum;

    @Length(min = 1, max = 200, message = "结算银行开户支行名称长度为1-200位")
    @NotBlank(message = "结算银行开户支行名称不能为空")
    @ApiModelProperty(value = "结算银行开户支行名称")
    private String settlementBankBranchName;

    @ApiModelProperty("等级")
    private Integer level;
    @ApiModelProperty("直推订单数（只要下单就算）")
    private Integer directOrderNumber;
    @ApiModelProperty("总佣金（下单 的时候加 ，已退单的时候减。其余时间不变 ）")
    private BigDecimal grossCommission;
    @ApiModelProperty("审核时间(通过-开通时间)")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date auditTime;
    @ApiModelProperty("上级id(邀请人id)")
    private String parentId;
    @ApiModelProperty("上级昵称(邀请人昵称)")
    private String parentUsername="";

    @ApiModelProperty("下级数量")
    @TableField(exist = false)
    private Integer childCount = 0;
    @ApiModelProperty("直销业绩")
    @TableField(exist = false)
    private Double lowerTotalPrice = 0D;
    @ApiModelProperty("佣金收益")
    @TableField(exist = false)
    private Double totalCommiss = 0D;
    @ApiModelProperty("订单金额")
    @TableField(exist = false)
    private Double totalOrderPrice = 0D;
    @ApiModelProperty("用户类型名称")
    @TableField(exist = false)
    private String role;
    @ApiModelProperty("用户类型")
    @TableField(exist = false)
    private Integer roleType;

    @ApiModelProperty("昵称")
    @TableField(exist = false)
    private String nickName = "";

    @ApiModelProperty("用户类型名称")
    @TableField(exist = false)
    private String lowerTypeName;
    @ApiModelProperty("用户类型")
    @TableField(exist = false)
    private Integer lowerType;
    @ApiModelProperty("分销收益")
    @TableField(exist = false)
    private Double earnings;
    @ApiModelProperty("头像")
    @TableField(exist = false)
    private String face = "";
    @ApiModelProperty("所在工会名称")
    @TableField(exist = false)
    private String unionName;
    @ApiModelProperty("所在工会id")
    @TableField(exist = false)
    private String unionId;
}